package com.melon.common.config.mybatis;

import com.melon.common.persistence.annotation.MyBatisDao;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * MyBatis扫描接口
 *
 * @author liuzh
 * @since 2015-12-19 14:46
 */
//@Configuration
//TODO 注意，由于MapperScannerConfigurer执行的比较早，所以必须有下面的注解
//@ConditionalOnClass({SqlSessionFactory.class, SqlSessionFactoryBean.class})
//@AutoConfigureAfter(MybatisAutoConfiguration.class)
public class MyBatisMapperScannerConfig {
    private static final Logger LOGGER = LoggerFactory.getLogger(MyBatisMapperScannerConfig.class);

    //@Bean
    public MapperScannerConfigurer mapperScannerConfigurer() {
        MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
        mapperScannerConfigurer.setSqlSessionFactoryBeanName("sqlSessionFactory");
        mapperScannerConfigurer.setBasePackage("com.melon.modules.*.dao");
        mapperScannerConfigurer.setAnnotationClass(MyBatisDao.class);
        LOGGER.debug("mapperScannerConfigurer ---------------------");
        return mapperScannerConfigurer;
    }

}
